﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Styx;
using Styx.Common;
using Styx.CommonBot;
using Styx.CommonBot.Routines;
using Styx.MemoryManagement;
using Styx.TreeSharp;
using Styx.WoWInternals.WoWObjects;
using Styx.WoWInternals;
using System.Windows.Media;

#region YBMOP Comments
// 12880 - Enrage - http://www.wowhead.com/spell=12880
// 46916 - Bloodsurge - http://www.wowhead.com/spell=46916
// 131116 - Raging Blow! - http://www.wowhead.com/spell=131116
// 86346 - Colossus Smash - http://www.wowhead.com/spell=86346
// 85730 - Deadly Calm - http://www.wowhead.com/spell=85730
// 12950 - Meat Cleaver - http://www.wowhead.com/spell=12950
// 1719 - Recklessness - http://www.wowhead.com/spell=1719
// 114207 - Skull Banner - http://www.wowhead.com/spell=114207
// 6673 - Battle Shout - http://www.wowhead.com/spell=6673
// 469 - Commanding Shout - http://www.wowhead.com/spell=469
// 32216 - Victorious - http://www.wowhead.com/spell=32216
// 2825 - Bloodlust - http://www.wowhead.com/spell=2825
// 80353 - Time Warp - http://www.wowhead.com/spell=80353
// Need to add: Gift of the Naaru - Rallying cry - Enraged Regen
#endregion

namespace YourBuddy_MoP
{
    public partial class main : CombatRoutine
    {
        #region Cooldown Rotation
        public void CDRotation()
        {
            {
                if (SpellManager.GlobalCooldown || StyxWoW.Me.IsCasting) { return; }
            }
            #region Begin Cooldown Rotation
            {
                if (YBMOP_Settings.Instance.CDO_RC && Me.CurrentTarget.HasAura(86346) && Me.HasAura(12880))
                    if (CastSpell("Recklessness"))
                        Logging.Write(Colors.DarkRed, "Casting (CDR): Recklessness");
            }
            {
                if (YBMOP_Settings.Instance.CDO_BR && Me.CurrentTarget.IsWithinMeleeRange && !Me.HasAura(12880))
                    if (CastSpell("Berserker Rage"))
                        Logging.Write(Colors.DarkRed, "Casting (CDR): Berserker Rage");
            }
            {
                if (
                    ((YBMOP_Settings.Instance.RTO_6 && YBMOP_Settings.Instance.RTO_Use == "Always") && (YBMOP_Settings.Instance.RTO_6 && SpellManager.HasSpell("Avatar") && (Me.HasAura(1719) || SpellManager.Spells["Recklessness"].CooldownTimeLeft.TotalSeconds >= 180))) ||
                    ((YBMOP_Settings.Instance.RTO_6 && YBMOP_Settings.Instance.RTO_Use == "On Bloodlust & Time Warp" && (Me.HasAura(2825) || Me.HasAura(80353))) && (YBMOP_Settings.Instance.RTO_6 && SpellManager.HasSpell("Avatar") && (Me.HasAura(1719) || SpellManager.Spells["Recklessness"].CooldownTimeLeft.TotalSeconds >= 180))) ||
                    ((YBMOP_Settings.Instance.RTO_6 && YBMOP_Settings.Instance.RTO_Use == "On Boss & Dummy" && (IsTargetBoss() || IsTargetDummy())) && (YBMOP_Settings.Instance.RTO_6 && SpellManager.HasSpell("Avatar") && (Me.HasAura(1719) || SpellManager.Spells["Recklessness"].CooldownTimeLeft.TotalSeconds >= 180)))
                    )
                    if (CastSpell("Avatar"))
                        Logging.Write(Colors.DarkRed, "Casting (CDR): Avatar");
            }
            {
                if (
                    ((YBMOP_Settings.Instance.RTO_6 && YBMOP_Settings.Instance.RTO_Use == "Always") && (YBMOP_Settings.Instance.RTO_6 && SpellManager.HasSpell("Bloodbath") && (Me.HasAura(1719) || SpellManager.Spells["Recklessness"].CooldownTimeLeft.TotalSeconds >= 10))) ||
                    ((YBMOP_Settings.Instance.RTO_6 && YBMOP_Settings.Instance.RTO_Use == "On Bloodlust & Time Warp" && (Me.HasAura(2825) || Me.HasAura(80353))) && (YBMOP_Settings.Instance.RTO_6 && SpellManager.HasSpell("Bloodbath") && (Me.HasAura(1719) || SpellManager.Spells["Recklessness"].CooldownTimeLeft.TotalSeconds >= 10))) ||
                    ((YBMOP_Settings.Instance.RTO_6 && YBMOP_Settings.Instance.RTO_Use == "On Boss & Dummy" && (IsTargetBoss() || IsTargetDummy())) && (YBMOP_Settings.Instance.RTO_6 && SpellManager.HasSpell("Bloodbath") && (Me.HasAura(1719) || SpellManager.Spells["Recklessness"].CooldownTimeLeft.TotalSeconds >= 10)))
                    )
                    if (CastSpell("Bloodbath"))
                        Logging.Write(Colors.DarkRed, "Casting (CDR): Bloodbath");
            }
            {
                if (YBMOP_Settings.Instance.CDO_DC && Me.CurrentRage >= 40 && CAddCount() < 3)
                    if (CastSpell("Deadly Calm"))
                        Logging.Write(Colors.DarkRed, "Casting (CDR): Deadly Calm");
            }
            {
                if (
                    ((YBMOP_Settings.Instance.WBO_WB == "Skull Banner" && YBMOP_Settings.Instance.WBO_Use == "Always") && (!Me.HasAura(114207))) ||
                    ((YBMOP_Settings.Instance.WBO_WB == "Skull Banner" && YBMOP_Settings.Instance.WBO_Use == "On Bloodlust & Time Warp" && (Me.HasAura(2825) || Me.HasAura(80353))) && (!Me.HasAura(114207))) ||
                    ((YBMOP_Settings.Instance.WBO_WB == "Skull Banner" && YBMOP_Settings.Instance.WBO_Use == "On Boss & Dummy" && (IsTargetBoss() || IsTargetDummy())) && (!Me.HasAura(114207)))
                    )
                    if (CastSpell("Skull Banner"))
                        Logging.Write(Colors.DarkRed, "Casting (CDR): Skull Banner");
            }
            {
                if (YBMOP_Settings.Instance.CDO_RC && Me.Race == WoWRace.Troll)
                    if (CastSpell("Berserking"))
                        Logging.Write(Colors.ForestGreen, "Casting (Racial): Berserking");
            }
            {
                if (YBMOP_Settings.Instance.CDO_RC && Me.Race == WoWRace.Orc)
                    if (CastSpell("Blood Fury"))
                        Logging.Write(Colors.ForestGreen, "Casting (Racial): Blood Fury");
            }
            {
                if (YBMOP_Settings.Instance.CDO_RC && Me.Race == WoWRace.Goblin)
                    if (CastSpell("Rocket Barrage"))
                        Logging.Write(Colors.ForestGreen, "Casting (Racial): Rocket Barrage");
            }
            {
                if (YBMOP_Settings.Instance.ORO_Trink1 && Me.Inventory.Equipped.Trinket1 != null && Me.Inventory.Equipped.Trinket1.Cooldown <= 0)
                    if (Me.Inventory.Equipped.Trinket1.Use())
                        Logging.Write(Colors.Cyan, "Casting (CDR): Trinket in slot 1");
            }
            {
                if (YBMOP_Settings.Instance.ORO_Trink2 && Me.Inventory.Equipped.Trinket2 != null && Me.Inventory.Equipped.Trinket2.Cooldown <= 0)
                    if (Me.Inventory.Equipped.Trinket2.Use())
                        Logging.Write(Colors.Cyan, "Casting (CDR): Trinket in slot 2");
            }
            #endregion
        }
        #endregion

        #region Interrupt Rotation
        public void InterruptRotation()
        {
            {
                if (SpellManager.GlobalCooldown || StyxWoW.Me.IsCasting) { return; }
            }
            #region Begin Interrupt Rotation
            {
                if (YBMOP_Settings.Instance.ORO_IR && Me.CurrentTarget.IsWithinMeleeRange && StyxWoW.Me.CurrentTarget.IsCasting && StyxWoW.Me.CanInterruptCurrentSpellCast)
                    if (CastSpell("Pummel"))
                        Logging.Write(Colors.Aqua, "Casting (Interrupt): Pummel");
            }
            #endregion
        }
        #endregion

        #region Shout Rotation
        public void ShoutRotation()
        {
            {
                if (SpellManager.GlobalCooldown || StyxWoW.Me.IsCasting) { return; }
            }
            #region Begin Shout Rotation
            {
                if (YBMOP_Settings.Instance.PCO_Shout == "Battle Shout" && ((!Me.HasAura(6673)) || (Me.RagePercent < 70 && !WoWSpell.FromId(6673).Cooldown)))
                    if (CastSpell("Battle Shout"))
                        Logging.Write(Colors.YellowGreen, "Casting (Shout): Battle Shout");
            }
            {
                if (YBMOP_Settings.Instance.PCO_Shout == "Commanding Shout" && ((!Me.HasAura(469)) || (Me.RagePercent < 70 && !WoWSpell.FromId(469).Cooldown)))
                    if (CastSpell("Commanding Shout"))
                        Logging.Write(Colors.YellowGreen, "Casting (Shout): Commanding Shout");
            }
            #endregion
        }
        #endregion

        #region AoE Rotation
        public void AoERotation()
        {
            {
                if (SpellManager.GlobalCooldown || StyxWoW.Me.IsCasting) { return; }
            }
            #region Begin Multiple Target Rotation
            {
                if (YBMOP_Settings.Instance.ORO_AOE && CAddCount() >= 2 && CAddCount() <= 3 && ((Me.CurrentRage > 80 && Me.HasGlyphInSlot(43399)) || (Me.CurrentRage > 60 && !Me.HasGlyphInSlot(43399)) || (Me.HasAura(85730) && Me.CurrentRage > 40 && Me.HasGlyphInSlot(43399)) || (Me.HasAura(85730) && Me.CurrentRage > 60 && !Me.HasGlyphInSlot(43399))))
                    if (CastSpell("Cleave"))
                        Logging.Write(Colors.Yellow, "Casting (MTR): Cleave");
            }
            {
                if (YBMOP_Settings.Instance.ORO_AOE && CAddCount() > 3 && ((Me.CurrentRage > 80 && Me.HasGlyphInSlot(43399)) || (Me.CurrentRage > 60 && !Me.HasGlyphInSlot(43399))))
                    if (CastSpell("Whirlwind"))
                        Logging.Write(Colors.Yellow, "Casting (MTR): Whirlwind");
            }
            {
                if (YBMOP_Settings.Instance.ORO_AOE && Me.HasAura(131116) && ((CAddCount() == 2 && Me.Auras["Meat Cleaver"].StackCount == 1) || (CAddCount() == 3 && Me.Auras["Meat Cleaver"].StackCount == 2) || (CAddCount() > 3 && Me.Auras["Meat Cleaver"].StackCount > 2)))
                    if (CastSpell("Raging Blow"))
                        Logging.Write(Colors.Yellow, "Casting (MTR): Raging Blow");
            }
            {
                if (
                    ((YBMOP_Settings.Instance.RTO_4 && YBMOP_Settings.Instance.RTO_Use == "Always") && (YBMOP_Settings.Instance.RTO_4 && SpellManager.HasSpell("Bladestorm") && !Me.CurrentTarget.HasAura(86346) && Me.CurrentTarget.HealthPercent >= 20 && SpellManager.Spells["Colossus Smash"].CooldownTimeLeft.TotalSeconds >= 5 && SpellManager.Spells["Bloodthirst"].CooldownTimeLeft.TotalSeconds >= 5 && CAddCount() >= 2)) ||
                    ((YBMOP_Settings.Instance.RTO_4 && YBMOP_Settings.Instance.RTO_Use == "On Bloodlust & Time Warp" && (Me.HasAura(2825) || Me.HasAura(80353))) && (YBMOP_Settings.Instance.RTO_4 && SpellManager.HasSpell("Bladestorm") && !Me.CurrentTarget.HasAura(86346) && Me.CurrentTarget.HealthPercent >= 20 && SpellManager.Spells["Colossus Smash"].CooldownTimeLeft.TotalSeconds >= 5 && SpellManager.Spells["Bloodthirst"].CooldownTimeLeft.TotalSeconds >= 5 && CAddCount() >= 2)) ||
                    ((YBMOP_Settings.Instance.RTO_4 && YBMOP_Settings.Instance.RTO_Use == "On Boss & Dummy" && (IsTargetBoss() || IsTargetDummy())) && (YBMOP_Settings.Instance.RTO_4 && SpellManager.HasSpell("Bladestorm") && !Me.CurrentTarget.HasAura(86346) && Me.CurrentTarget.HealthPercent >= 20 && SpellManager.Spells["Colossus Smash"].CooldownTimeLeft.TotalSeconds >= 5 && SpellManager.Spells["Bloodthirst"].CooldownTimeLeft.TotalSeconds >= 5 && CAddCount() >= 2))
                    )
                    if (CastSpell("Bladestorm"))
                        Logging.Write(Colors.Yellow, "Casting (MTR): Bladestorm");
            }
            #endregion
        }
        #endregion

        #region Single Target Rotation
        public void STRotation()
        {
            {
                if (SpellManager.GlobalCooldown || StyxWoW.Me.IsCasting) { return; }
            }
            #region Begin Single-Target Rotation
            {
                if (CastSpell("Bloodthirst"))
                    Logging.Write(Colors.Orange, "Casting (STR): Bloodthirst");
            }
            {
                if (!Me.CurrentTarget.HasAura(86346))
                    if (CastSpell("Colossus Smash"))
                        Logging.Write(Colors.Orange, "Casting (STR): Colossus Smash");
            }
            {
                if (Me.CurrentTarget.HealthPercent <= 20)
                    if (CastSpell("Execute"))
                        Logging.Write(Colors.Orange, "Casting (STR): Execute");
            }
            {
                if (Me.HasAura(131116))
                    if (CastSpell("Raging Blow"))
                        Logging.Write(Colors.Orange, "Casting (STR): Raging Blow");
            }
            {
                if (Me.HasAura(46916) && Me.CurrentTarget.HealthPercent >= 20)
                    if (CastSpell("Wild Strike"))
                        Logging.Write(Colors.Orange, "Casting (STR): Wild Strike");
            }
            {
                if (SpellManager.Spells["Heroic Strike"].CooldownTimeLeft.TotalSeconds <= 0 && ((Me.CurrentRage > 80 && Me.HasGlyphInSlot(43399)) || (Me.CurrentRage > 60 && !Me.HasGlyphInSlot(43399)) || (Me.HasAura(85730) && Me.CurrentRage > 40 && Me.HasGlyphInSlot(43399)) || (Me.HasAura(85730) && Me.CurrentRage > 60 && !Me.HasGlyphInSlot(43399))))
                    if (CastSpell("Heroic Strike"))
                        Logging.Write(Colors.Orange, "Casting (STR): Heroic Strike");
            }
            {
                if  (
                    ((YBMOP_Settings.Instance.RTO_6 && YBMOP_Settings.Instance.RTO_Use == "Always") && (YBMOP_Settings.Instance.RTO_6 && SpellManager.HasSpell("Storm Bolt"))) ||
                    ((YBMOP_Settings.Instance.RTO_6 && YBMOP_Settings.Instance.RTO_Use == "On Bloodlust & Time Warp" && (Me.HasAura(2825) || Me.HasAura(80353))) && (YBMOP_Settings.Instance.RTO_6 && SpellManager.HasSpell("Storm Bolt"))) ||
                    ((YBMOP_Settings.Instance.RTO_6 && YBMOP_Settings.Instance.RTO_Use == "On Boss & Dummy" && (IsTargetBoss() || IsTargetDummy())) && (YBMOP_Settings.Instance.RTO_6 && SpellManager.HasSpell("Storm Bolt")))
                    )
                    if (CastSpell("Storm Bolt"))
                        Logging.Write(Colors.Orange, "Casting (STR): Storm Bolt");
            }
            {
                if (
                    ((YBMOP_Settings.Instance.RTO_4 && YBMOP_Settings.Instance.RTO_Use == "Always") && (YBMOP_Settings.Instance.RTO_4 && SpellManager.HasSpell("Shockwave"))) ||
                    ((YBMOP_Settings.Instance.RTO_4 && YBMOP_Settings.Instance.RTO_Use == "On Bloodlust & Time Warp" && (Me.HasAura(2825) || Me.HasAura(80353))) && (YBMOP_Settings.Instance.RTO_4 && SpellManager.HasSpell("Shockwave"))) ||
                    ((YBMOP_Settings.Instance.RTO_4 && YBMOP_Settings.Instance.RTO_Use == "On Boss & Dummy" && (IsTargetBoss() || IsTargetDummy())) && (YBMOP_Settings.Instance.RTO_4 && SpellManager.HasSpell("Shockwave")))
                    )
                    if (CastSpell("Shockwave"))
                        Logging.Write(Colors.Orange, "Casting (STR): Shockwave");
            }
            {
                if (
                    ((YBMOP_Settings.Instance.RTO_4 && YBMOP_Settings.Instance.RTO_Use == "Always") && (SpellManager.HasSpell("Dragon Roar") && Me.CurrentTarget.IsWithinMeleeRange)) ||
                    ((YBMOP_Settings.Instance.RTO_4 && YBMOP_Settings.Instance.RTO_Use == "On Bloodlust & Time Warp" && (Me.HasAura(2825) || Me.HasAura(80353))) && (SpellManager.HasSpell("Dragon Roar") && Me.CurrentTarget.IsWithinMeleeRange)) ||
                    ((YBMOP_Settings.Instance.RTO_4 && YBMOP_Settings.Instance.RTO_Use == "On Boss & Dummy" && (IsTargetBoss() || IsTargetDummy())) && (SpellManager.HasSpell("Dragon Roar") && Me.CurrentTarget.IsWithinMeleeRange))
                    )
                    if (CastSpell("Dragon Roar"))
                        Logging.Write(Colors.Orange, "Casting (STR): Dragon Roar");
            }
            {
                if (YBMOP_Settings.Instance.ORO_HT && StyxWoW.Me.Inventory.Equipped.MainHand != null)
                    if (CastSpell("Heroic Throw"))
                        Logging.Write(Colors.Orange, "Casting (STR): Heroic Throw");
            }
            {
                if (YBMOP_Settings.Instance.ORO_ST && StyxWoW.Me.Inventory.Equipped.MainHand != null)
                    if (CastSpell("Shattering Throw"))
                        Logging.Write(Colors.Orange, "Casting (STR): Shattering Throw");
            }
            #endregion
        }
        #endregion

        #region Self Heal Rotation
        public void SHRotation()
        {
            {
                if (SpellManager.GlobalCooldown || StyxWoW.Me.IsCasting) { return; }
            }
            #region Begin Self Heal Rotation
            {
                if ((YBMOP_Settings.Instance.ORO_SH) && (SpellManager.HasSpell("Impending Victory") && Me.CurrentHealth <= 25))
                    if (CastSpell("Impending Victory"))
                        Logging.Write(Colors.Blue, "Casting (SH): Impending Victory");
            }
            {
                if ((YBMOP_Settings.Instance.ORO_SH) && (Me.CurrentHealth <= 25))
                    if (CastSpell("Enraged Regeneration"))
                        Logging.Write(Colors.Blue, "Casting (SH): Enraged Regeneration");
            }
            {
                if ((YBMOP_Settings.Instance.ORO_SH) && (SpellManager.HasSpell("Victory Rush") && Me.HasAura(32216) && Me.CurrentHealth <= 15))
                    if (CastSpell("Victory Rush"))
                        Logging.Write(Colors.Blue, "Casting (SH): Victory Rush");
            }
            #endregion
        }
        #endregion

    }
}